package com.example.myapplication8;
// DetailActivity.java
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.example.myapplication8.databinding.ActivityDetailBinding;

public class DetailActivity extends AppCompatActivity {
    private ActivityDetailBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityDetailBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        DataModel item = (DataModel) getIntent().getSerializableExtra("data");
        if (item != null) {
            binding.tvTitle.setText(item.getTitle());
            binding.tvContent.setText(item.getContent());
        } else {
            binding.tvTitle.setText("数据加载失败");
            binding.tvContent.setText("无法获取详细信息");
        }
    }

    public static Intent newIntent(Context context, DataModel data) {
        Intent intent = new Intent(context, DetailActivity.class);
        intent.putExtra("data", data);
        return intent;
    }
}